#!/bin/sh
LC_ALL=C

# Select files to format
FILES=$(git show --name-only --pretty="")
[ -z "$FILES" ] && exit 0

# Format all selected files with dotnet-format
echo "dotnet-format: Formatting changed source files.."
echo "$FILES" | cat | xargs | sed -e 's/ /,/g' | xargs dotnet-format --folder . --include >/dev/null
echo "dotnet-format: $(git diff --cached --numstat | wc -l) file(s) formatted."

# Add files to staging
echo "$FILES" | xargs git add
exit 0